package com.huangmb.anymark.server.utils;
/**
 * 安全类型转换工具类
 *
 * @author hmb
 * @version 1.0
 * @since 2016/4/12 20:56
 */
public class Converter {

    public static int toInt(Object obj,int defaultValue){
        if(obj != null && !"".equals(obj.toString().trim())){
            try{
                return Integer.valueOf(obj.toString());
            }catch (Exception e){
                try {
                    return Double.valueOf(obj.toString()).intValue();
                }catch (Exception e1){
                    return defaultValue;
                }
            }
        }
        return defaultValue;
    }
    public static double toDouble(Object obj,double defaultValue){
        if(obj != null && !"".equals(obj.toString().trim())){
            try{
                return Double.valueOf(obj.toString());
            }catch (Exception e){
                return defaultValue;
            }
        }
        return defaultValue;
    }
}
